
package com.android.finaltracer.test;

import java.util.HashMap;
import java.util.Map;

import android.test.InstrumentationTestCase;

import com.android.finaltracer.util.Bean;

public class BeanUtilTestCase extends InstrumentationTestCase {

    public void testBean2Map() {
        ObjectSon obj = new ObjectSon();
        obj.setGender("man manster");
        Map<String, Object> result = Bean.bean2Map(obj);
        assertEquals(4, result.size());
        assertEquals("Leeon", result.get("name"));
        assertEquals("man manster", result.get("gender"));
        assertEquals("RR", result.get("car"));
        assertEquals(30, result.get("age"));

        assertNull(result.get("secrect"));
        assertNull(result.get("latitude"));
    }

    public void testMap2Bean() {
        Map<String, String> stringMap = new HashMap<String, String>();
        stringMap.put("name", "Leeon");
        stringMap.put("gender", "boy");
        stringMap.put("car", "Lamborghini");
        stringMap.put("age", "30");
        stringMap.put("latitude", "343.44");
        stringMap.put("longitude", "123.33");

        ObjectSon obj = Bean.map2Bean(stringMap, ObjectSon.class);
        assertEquals("Leeon", obj.getName());
        assertEquals("boy", obj.getGender());
        assertEquals("Lamborghini", obj.getCar());
        assertEquals(30, obj.getAge());
        assertEquals(343.44, obj.getLatitude());
        assertEquals(123.33, obj.getLongitude());
    }
}
